/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.benimetum.managers;

import com.benimetum.managers.CourseManager;
import java.io.File;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class XMLParser_For_Student {
    public static void main(String argv[]){
       String email = null;
       String id = null;
	 String password = null;
       String firstName = null;
       String lastName = null;
       String status  = null;
       String profilePicture = null;
       String Mentor = null;
       String MentorID = null;
          
       try{
           File fXmlFile = new File("students.xml");
		DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
		DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
		Document doc = dBuilder.parse(fXmlFile);
		doc.getDocumentElement().normalize();
                
                NodeList nList = doc.getElementsByTagName("student");
		
               for (int temp = 0; temp < nList.getLength(); temp++) {
 
		   Node nNode = nList.item(temp);
		  
		   if (nNode.getNodeType() == Node.ELEMENT_NODE) {
 
		      Element eElement = (Element) nNode;
 
		      
                      email = getTagValue("email", eElement);
                      id = getTagValue("id", eElement);
                      firstName = getTagValue("firtName", eElement);
	              lastName = getTagValue("lastName", eElement);
                      status = getTagValue("status", eElement);
			    password = getTagValue("password", eElement);
                      profilePicture = getTagValue("profilePicture", eElement);
                      Mentor = getTagValue("mentor", eElement);
                      MentorID = getTagValue("mentorID",eElement);
                      System.out.println(email+" "+id+" "+firstName+" "+lastName+" "+status+" "+profilePicture+" "+Mentor+" "+MentorID);
                   
                       
                      }
                   StudentManager.createStudent(email, password, id, firstName, lastName, "img/defaultProfile.jpg", "t"+MentorID);
                }
       }
       catch (Exception e) {
	  }
    
    
    
    }

    private static String getTagValue(String sTag, Element eElement){
        NodeList nlList = eElement.getElementsByTagName(sTag).item(0).getChildNodes();
        Node nValue = (Node) nlList.item(0);
        return nValue.getNodeValue();
       
    }
    
}
